package com.yanqu.road.server.cmd.activity.feast.pvp;

import com.yanqu.road.entity.activity.feast.config.ShanHeFeastConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.feast.CrossFeastMgr;
import com.yanqu.road.server.manager.activity.feast.activity.CrossFeastActivity;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_SHAN_HE_FEAST_JUMP, desc = "传送位置")
public class CrossFeastPositionJumpCmd extends CrossCommand {


    long userId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        ShanHeFeastProto.CrossFeastPositionJumpReqMsg jumpReqMsg = ShanHeFeastProto.CrossFeastPositionJumpReqMsg.parseFrom(packet.getBytes());
        CrossFeastActivity activity = CrossFeastMgr.getActivity(jumpReqMsg.getActivityId());
        if (activity == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_ACTIVITY_NOT_FOUND;
            return;
        }
        ShanHeFeastConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_CONFIG_NOT_FOUND;
            return;
        }
        ret = activity.jumpByCmd(serverId, packet.getPlayerId(), activity.parseCrossFeastPvpPosition(jumpReqMsg.getPosition()));
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            ShanHeFeastProto.FeastPositionJumpRespMsg.Builder respMsg = ShanHeFeastProto.FeastPositionJumpRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.U_SHAN_HE_FEAST_JUMP, respMsg));
        }
    }
}
